package com.linkedList;

public class LinkedListCycleII0129_142 {
    public ListNode detectCycle(ListNode head) {
        ListNode fast = head, low = head;

        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            low = low.next;
            if (fast == low) {
                ListNode res = head;

                while (res != low){
                    res = res.next;
                    low = low.next;
                }

                return low;
            }
        }
        return null;
    }
}
